import { Main } from 'element-ui'
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/login",
    name:"login",
    component:()=>import("../views/Login")
  },
  {
    path: '/',
    name: 'Home',
    redirect:"/my",
    component: Home,
    children:[
      {
        path:"main",
        name:"main",
        component:()=>import("../views/main/index"),
        children:[
          {
            path:"/my",
            name:"my",
            component:()=>import("../views/main/My")
          },
          {
            path:"/you",
            name:"you",
            component:()=>import("../views/main/You")
          },
          {
            path:"/he",
            name:"he",
            component:()=>import("../views/main/He")
          },
          {
            path:"/list",
            name:"list",
            component:()=>import("../views/main/List")
          },
          {
            path:"/list1",
            name:"list1",
            component:()=>import("../views/main/List1")
          },
          {
            path:"/list2",
            name:"list2",
            component:()=>import("../views/main/List2")
          }
        ]
      },
      {
        path:"work",
        name:"work",
        component:()=>import("../views/work/index")
      },
      {
        path:"news",
        name:"news",
        component:()=>import("../views/news/index")
      },
      {
        path:"order",
        name:"order",
        component:()=>import("../views/order/index")
      }
    ]
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  }
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to,from,next)=>{
  if(localStorage.getItem('token')){
    next()
  }else{
    if(to.path == "/login"){
      next()
    }else{
      next("/login")
    }
  }
})

export default router
